package com.njzxw.yoga.yogaApi.repository;

import com.njzxw.fs.commonutil.db.ZxwLangDriver;
import org.apache.ibatis.annotations.*;
import com.njzxw.yoga.yogaApi.bean.ShopInfoBean;


import java.util.List;
import java.util.Map;

@Mapper
public interface ShopInfoRepository {

    @Select("select e.name oper_name, a.shop_tel, a.id,a.shop_name,a.shop_pic,a.shop_desc," +
            "       a.shop_mor_start,a.shop_mor_end,a.shop_after_start,a.shop_after_end," +
            "       a.shop_province,a.shop_city,a.shop_district,a.shop_address," +
            "       a.shop_province shop_district0,a.shop_city shop_district1,a.shop_district shop_district2," +
            "       a.shop_long,a.shop_lat,DATE_FORMAT(a.shop_bgtime,'%Y-%m-%d %T') shop_bgtime,DATE_FORMAT(a.shop_endtime,'%Y-%m-%d %T') shop_endtime,  " +
            " a.shop_orderby,a.merchant_id,a.shop_status,a.oper_id,DATE_FORMAT(a.oper_date,'%Y-%m-%d %T') oper_date,DATE_FORMAT(a.update_oper_id,'%Y-%m-%d %T') update_oper_id,DATE_FORMAT(a.update_oper_date,'%Y-%m-%d %T') update_oper_date,a.msm_num " +
            " from t_shop_info a left join t_manager_user e on a.oper_id = e.id " +
            " where 1=1 " +
            "   and a.shop_name like #{shop_name} " +
            "   and a.shop_desc like #{shop_desc} " +
            "   and a.shop_province = #{shop_province} " +
            "   and a.shop_city = #{shop_city} " +
            "   and a.shop_district = #{shop_district}" +
            "   and a.shop_address like #{shop_address} " +
            "   and a.shop_tel like #{shop_tel} " +
            "   and a.shop_status = #{shop_status} " +
            "   and DATE_FORMAT(a.oper_date,'%Y-%m-%d %T') >= #{min_oper_date}" +
            "   and DATE_FORMAT(a.oper_date,'%Y-%m-%d %T') <= #{max_oper_date} " +
            "   ")
    @Lang(ZxwLangDriver.class)
    List<Map<String,Object>> queryPage(ShopInfoBean shopInfoBean);

    @Select("select e.name oper_name, a.shop_tel, a.id,a.shop_name,a.shop_pic,a.shop_desc,a.shop_mor_start,a.shop_mor_end,a.shop_after_start,a.shop_after_end,a.shop_province,a.shop_city,a" +
            ".shop_district,a.shop_address,a.shop_long,a.shop_lat,DATE_FORMAT(a.shop_bgtime,'%Y-%m-%d %T') shop_bgtime,DATE_FORMAT(a.shop_endtime,'%Y-%m-%d %T') shop_endtime,a.shop_orderby,a.merchant_id,a.shop_status,a.oper_id,DATE_FORMAT(a.oper_date,'%Y-%m-%d %T') oper_date,DATE_FORMAT(a.update_oper_id,'%Y-%m-%d %T') update_oper_id,DATE_FORMAT(a.update_oper_date,'%Y-%m-%d %T') update_oper_date,a.msm_num from t_shop_info a left join t_manager_user e on a.oper_id = e.id where a.id = #{id}")
    Map<String,Object> queryId(ShopInfoBean shopInfoBean);

    @Update("update t_shop_info a (#{shopInfoBean}) where  a.id = #{id}")
    @Lang(ZxwLangDriver.class)
    Integer update(ShopInfoBean shopInfoBean);

    @Delete("delete a from t_shop_info a where  a.id in (#{ids})")
    @Lang(ZxwLangDriver.class)
    Integer delete(ShopInfoBean shopInfoBean);

    @Insert("insert into t_shop_info(#{shopInfoBean})")
    @Lang(ZxwLangDriver.class)
    @Options(useGeneratedKeys = true)
    Integer insert(ShopInfoBean shopInfoBean);

    @Select("select c.id,c.org_name ,c.supper_id,e.org_name supper_name \n" +
            "  from t_manager_user a,t_manager_user_org b,t_manager_org c,t_manager_org e  \n" +
            " where a.id = b.manager_user_id \n" +
            "   and c.supper_id = e.id and e.state = 1 and c.state = 1 \n" +
            "   and b.manager_org_id = c.id\n" +
            "   and a.id = #{user_id} \n " +
            "   and c.is_terrace = 0 " +
            "\t and c.`level` = #{level}")
    @Lang(ZxwLangDriver.class)
    List<Map<String,Object>> getUserMerchantShop(@Param("user_id") String user_id,@Param("level") String level);

}

